package com.healthcloud.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.healthcloud.entity.AppVersion;
import com.healthcloud.entity.MobileModel;
import com.healthcloud.service.AppVersionService;
import com.healthcloud.service.MobileModelService;
import com.healthcloud.utils.ApiRes;
import springfox.documentation.annotations.ApiIgnore;

/**
 * Created by XYC on 2015/7/28.
 */
@ApiIgnore
@Api(value = "示例说明", description = "app版本信息")
@RestController
@RequestMapping(value = "/app/dean/baseOperate")
public class BaseOperateController {

    @Autowired
    private AppVersionService appVersionService;
    @Autowired
    private MobileModelService mobileModelService;

    /**
     * 获取app版本信息精简版
     * @param appVersion
     * @return
     */
	@ApiOperation(value = "获取app版本信息精简版",notes ="获取app版本信息精简版")
    @RequestMapping(value = "/appVersion/Get",method = RequestMethod.POST)
    public Object findNewAppVersion(AppVersion appVersion){
//        AppVersion appVersions = appVersionService.findListAppVersionWithMobileOS(appVersion);
        if(appVersion.getAppCode()==null){
            appVersion.setAppCode("-1");
        }

        ArrayList<AppVersion> appVersions = appVersionService.findByAppCode(appVersion);
        AppVersion appVersion1=null;
        ApiRes apiRes =new ApiRes("");
        if (appVersions.isEmpty()){
            apiRes.setSuccess(false);
            apiRes.setMsg("该版本不存在，请核对appCode");
        }else{
//            appVersion1 = appVersionService.phoneAppNeedData(appVersions.get(appVersions.size() - 1));
            apiRes.setData(appVersionService.phoneAppNeedHashMap(appVersions.get(appVersions.size() - 1)));
        }
        return apiRes;
    }

    /**
     * 获取app版本信息全信息版本
     * @param appVersion
     * @return
     */
	@ApiOperation(value = "获取app版本信息全信息版本",notes ="获取app版本信息全信息版本")
    @RequestMapping(value = "/appPadVersion/Get",method = RequestMethod.POST)
    public Object findPadVersion(AppVersion appVersion){
//        AppVersion appVersions = appVersionService.findListAppVersionWithMobileOS(appVersion);
        if(appVersion.getAppCode()==null){
            appVersion.setAppCode("-1");
        }
        ArrayList<AppVersion> appVersions = appVersionService.findByAppCode(appVersion);
        AppVersion appVersion1=null;
        ApiRes apiRes =new ApiRes("");
        if (appVersions.isEmpty()){
            apiRes.setSuccess(false);
            apiRes.setMsg("该版本不存在，请核对appCode");
        }else{
            apiRes.setData( appVersionService.changeTimeShow(appVersions.get(appVersions.size() - 1)));
        }
        return apiRes;
    }

    @Deprecated
    @RequestMapping(value = "/mobileModel/Get",method = RequestMethod.POST)
    public Object findAllMobileModel(MobileModel mobileModel){
        ArrayList<MobileModel> mobileModels =mobileModelService.findAll();
        return new ApiRes(mobileModels);

    }
}
